package com.wuhainan.beelzebub.service.system;

import com.wuhainan.beelzebub.common.BaseService;
import com.wuhainan.beelzebub.entity.system.User;
import com.wuhainan.beelzebub.repository.system.UserRepository;
import com.wuhainan.beelzebub.utils.PageInfo;
import com.wuhainan.beelzebub.utils.TableData;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <br>Created by 吴海南 on 2017-12-18.
 * <br>星期一 at 下午 3:05.
 */
@Service
public class UserService extends BaseService<User>{
    @Resource
    private UserRepository repository;

    public User findOne(String id) {
        return repository.findOne(id);
    }

    public TableData findUserPage(PageInfo pageInfo, User user) {
        Page<User> page=repository.findAll((root, cq, cb) -> {
            search(user, cq, cb, root);//模糊查询
            return cq.getRestriction();
        },pageable(pageInfo,sort(pageInfo, Sort.Direction.ASC,"id")));
        return tableData(page);
    }

    public User findUserById(String id) {
        return repository.findOne(id);
    }

    public void saveUser(User user) {
        repository.save(user);
    }

    public void deleteUser(User user) {
        repository.save(user);
    }

    public void restoreUser(User user) {
        repository.save(user);
    }
}
